package com.pp.pingpong;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainMenu extends Activity{
	
	private Button newGame;
	private Button configuration;
	
	public static final String PREFS_NAME = "PingPong";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_menu);	
		
		newGame = (Button) findViewById(R.id.button1);
		configuration = (Button) findViewById(R.id.button2);
		LoadConfiguration();
		newGame.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {			
				 Intent intent = new Intent(MainMenu.this, GameActivity.class);
				 MainMenu.this.startActivity(intent);
				 //MainMenu.this.finish();
			}	
		});
		
		configuration.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {			
				 Intent intent = new Intent(MainMenu.this, ConfigurationActivity.class);
				 MainMenu.this.startActivity(intent);
				 //MainMenu.this.finish();
			}	
		});
	
		
	}
	
	public void LoadConfiguration() {		
		SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);	    
	    Config.getInstance().setIpAddress(settings.getString("ipAddress", ""));
	    Config.getInstance().setPortNumber(settings.getString("portNumber", ""));
	    Config.getInstance().setNickName(settings.getString("nickName", ""));	
	}
	
	

}
